package cn.cmvideo.springboot;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class CyclicBarrierCase
{
	private static CyclicBarrier c = new CyclicBarrier(2);
	
	public static void main(String[] args)
	{
		for(int i = 0; i < 3; i++)
		{
			new Thread(new Runnable()
			{
				
				@Override
				public void run()
				{
					try
					{
						c.await();
						System.out.println(Thread.currentThread().getName());
					} catch (InterruptedException | BrokenBarrierException e)
					{
						e.printStackTrace();
					}
				}
			}).start();
		}
		
//		int numberWaiting = c.getNumberWaiting();
//		if(numberWaiting > 0)
//		{
//			System.out.println(numberWaiting);
//			c.reset();
//		}
		
		try
		{
			c.await();
		} catch (InterruptedException | BrokenBarrierException e)
		{
			e.printStackTrace();
		}
		System.out.println(Thread.currentThread().getName());
		
		
		
	}

}
